#ifndef __MCS__EXPRESSION_ELEMENT__HPP
#define __MCS__EXPRESSION_ELEMENT__HPP

#include "Element.hpp"
#include "Expression.hpp"

//! Evaluates expression and outputs its result with default formatting.
class ExpressionElement : public Element
{
public:
	ExpressionElement(SourceLocation const & location, ptr<Expression> expr)
		: Element(location)
		, expr_(expr)
	{}

	virtual void init(Block * parentBlock)
	{
		Element::init(parentBlock);
		expr_->init(parentBlock);
	}

	virtual void execute() const
	{
		ptr<Value> val = expr_->evaluate();
		String str = val->toString();
		parentBlock()->outputStream() << str;
	}
private:
	ptr<Expression> expr_;
};

#endif //__MCS__EXPRESSION_ELEMENT__HPP
